﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Data.NHibernate.Generic.Support;

namespace Mani.Patient.Business.Dao {

    public interface IDao<T> {

        T FindById(object id);

        IList<T> FindAll();

        T SaveOrUpdate(T entity);

        void Delete(T entity);
    }

    public abstract class DaoBase<T> : HibernateDaoSupport, IDao<T> {

        public T FindById(object id) {
            return HibernateTemplate.Get<T>(id);
        }

        public IList<T> FindAll() {
            return HibernateTemplate.LoadAll<T>();
        }

        public T SaveOrUpdate(T entity) {
            HibernateTemplate.SaveOrUpdate(entity);
            return entity;
        }

        public void Delete(T entity) {
            HibernateTemplate.Delete(entity);
        }
    }
}
